class Node:#定义节点
    def __init__(self,name,type='dir'):
        self.name=name
        self.type=type #"dir"or"file"
        self.children=[]#子(往下指)
        self.parent=None#父(往上指)
        #链式储存
    def __repr__(self):
        return self.name
class FileSystemTree:
    def __init__(self) :
        self.root=Node("/")#linux系统的目录:/var/bin
        self.now=self.root#当前所在的节点(这这个指当前文件夹所在的位置)
    def mkdir(self,name):#当前文件夹创建文件
        #name以 /结尾
        if name[-1]!="/":
            name+="/"
        node=Node(name)
        self.now.children.append(node)
        node.parent=self.now
    def ls(self):
        return self.now.children
    def cd(self,name):#目前是相对路径，只支持往下走
        if name[-1]!="/":
            name+="/"
        if name=="../":#支持打印向上
            self.now=self.now.parent
            return
        for child in self.now.children:
            if child.name==name:
                self.now=child
                return
        raise ValueError("invalid   dir")
if __name__=="__main__":
    '''n=Node("hello")
    n2=Node("world")
    n.children.append(n2)
    n2.parent=n'''
    
    tree=FileSystemTree()
    tree.mkdir("var/")
    tree.mkdir("bin/")
    tree.mkdir("user/")

    tree.cd("bin/")
    tree.mkdir("python/")
    tree.cd("../")#这是向上打印的
    print(tree.ls())